﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Core.Dtos;
using Core.Messages;
using Core.Queries;
using Core.IRepository;
using Core.Domain;
using Library.Helpers;
using Front.Controllers.Api;
using System.IO;
using System.Collections;
using Core.IServices;
using Library.Logging;
using Core.Factories;
using Core.Context;
using System.Web.Http.Cors;
using Share.Enterprise.Api;

namespace Front.Areas.Admin.Controllers.Api
{
    [RoutePrefix("api/admin/logs")]
    //[Authorize(Roles = "Admin")]
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    public class LogApiController : IQueryApiController<int, LogDto, LogQuery>
    {
        private readonly IManageLogService service;
        private readonly IRequestFactory requestFactory;
        private readonly ICurrentContext currentContext;

        public LogApiController(IManageLogService service, ILogger logger, ICurrentContext currentContext, IRequestFactory requestFactory)            
        {
            this.service = service;
            this.requestFactory = requestFactory;
            this.currentContext = currentContext;
        }

        [HttpPost]
        [Route("searches")]
        public QueryResponse<LogDto> FindBy(LogQuery query)
        {
            Request<LogQuery> request = requestFactory.GetInstance<LogQuery>(query);
            return service.FindBy(request);
        }

        [Route("{id}")]
        public LogDto Get(int id)
        {
            return service.FindByID(id);
        }

        [HttpDelete]
        [Route("{id}")]
        public Response Delete(int id)
        {
            return service.Delete(id);
        }

        [HttpDelete]
        [Route("old")]
        public Response DeleteOld()
        {
            return service.DeleteOld();
        }
    }
}